//! @Author: DengLibin
//! @Date: Create in 2024-01-29 16:50:27
//! @Description: 队列

use std::collections::LinkedList;


//使用链表实现一个队列
struct Queue<T> {
    size: usize,
    data: LinkedList<T>,
}

impl <T> Queue<T>{
    fn new()->Self {
        Queue {
            size: 0,
            data: LinkedList::new(),
        }
    }

    //入队
    fn enqueue(&mut self, val: T) {
        self.data.push_back(val);
        self.size += 1;
    }

    //出队
    fn dequeue(&mut self)->Option<T>{
        if self.size == 0 {
            return None;
        }
        self.size -= 1;
        self.data.pop_front()
    }

    fn is_empty(&self)->bool {
        self.size == 0
    }

}

pub fn hello_queue(){
    let mut q = Queue::new();
    q.enqueue(1);
    q.enqueue(2);
    q.enqueue(3);
    while !q.is_empty() {
        if let Some(v) = q.dequeue() {
            println!("出队：{}", v);
        }
    }
}